﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineHelpDesk.Requestor;
using OnlineHelpDesk.BLL_Service;

namespace OnlineHelpDesk.Requestor
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        Service1 s = new Service1();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblUserName.Text = Session["UserName"].ToString();
            }

        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {

            string userName = Session["UserName"].ToString();
            En_Users eu = s.getUserbyName(userName);
            string olsPassword = eu.UserPassword.ToString();
            if (txtPassword.Text != olsPassword)
            {
                Response.Write("<script>alert('Old Password is error , try again!!');</script>");
                txtPassword.Text="";
                txtPassword.Focus();
            }
            else if (txtNewPassword.Text != txtConfirmPassword.Text)
            {
                Response.Write("<script>alert('New Passwrd and Confirm Password must be the same!!');</script>");
                txtNewPassword.Text = "";
                txtConfirmPassword.Text = "";
                txtNewPassword.Focus();
            }
            else
            {
                s.UpdatePassword(userName, txtNewPassword.Text.ToString());
                Response.Write("<script>alert('Change Password is Succefull!!');</script>");
                txtPassword.Text = "";
                txtNewPassword.Text = "";
                txtConfirmPassword.Text = "";
                txtPassword.Focus();

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            txtPassword.Text = "";
            txtNewPassword.Text = "";
            txtConfirmPassword.Text = "";
            txtPassword.Focus();
        }
    }
}